package main

import (
	"encoding/json"
	"fmt"
)

/*
√ 使用Person结构体描述谦哥并转JSON
√ 使用map[string]interface{}描述谦哥并转JSON
√ 使用map切片描述谦哥的小姨子们并转JSON
*/

type Person struct {
	Name string
	Age int
	Rmb float64
	Sex bool
	Hobby []string
}

/*使用Person结构体描述谦哥并转JSON*/
func main0211() {
	person := Person{"于谦", 50, 123.45, true, []string{"抽烟", "喝酒", "烫头"}}
	bytes, e := json.Marshal(person)
	if e != nil{
		fmt.Println("序列化失败,err=",e)
		return
	}
	fmt.Println(string(bytes))
}

/*使用map[string]interface{}描述谦哥并转JSON*/
func main0222() {
	dataMap := make(map[string]interface{})
	dataMap["name"] = "于谦"
	dataMap["age"] = 50
	dataMap["rmb"] = 123.45
	dataMap["sex"] = true
	dataMap["hobby"] = []string{"抽烟", "喝酒", "烫头"}

	bytes, e := json.Marshal(dataMap)
	if e != nil{
		fmt.Println("序列化失败,err=",e)
		return
	}
	fmt.Println(string(bytes))
}

/*使用map切片描述谦哥的小姨子们并转JSON*/
func main() {
	dataMap1 := make(map[string]interface{})
	dataMap1["name"] = "王钢蛋"
	dataMap1["hobby"] = []string{"抽中华", "喝牛栏山", "烫花卷头"}

	dataMap2 := make(map[string]interface{})
	dataMap2["name"] = "王铁蛋"
	dataMap2["hobby"] = []string{"抽玉溪", "喝五粮液", "烫杀马特"}

	dataMap3 := make(map[string]interface{})
	dataMap3["name"] = "王铜蛋"
	dataMap3["hobby"] = []string{"抽小熊猫", "喝剑南春", "烫鸡冠头"}

	dataSlice := make([]map[string]interface{}, 0)
	dataSlice = append(dataSlice, dataMap1, dataMap2, dataMap3)

	bytes, e := json.Marshal(dataSlice)
	if e != nil{
		fmt.Println("序列化失败,err=",e)
		return
	}
	fmt.Println(string(bytes))
}